/**
 * 
 */
package com.vincent.dao;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.stereotype.Component;

import com.vincent.common.Constant_Credits;
import com.vincent.dao.basic.BasicDao;
import com.vincent.pojo.Credits;
import com.vincent.pojo.User;

/**
 * 作者： Vincent 创建日期： 2014年4月20日 上午11:05:09 项目名字： MyForum
 */
@Component("creditsDao")
public class CreditsDAO extends BasicDao<Credits> {

	public int getCreditsSum(User u) {
		
		String hqlString = "SELECT SUM(c.num) FROM Credits c WHERE c.user = ?";
		
		Object[] parameters = { u };

		return (int) this.executeQueryUniqueResult(hqlString, parameters);
	}

	public Credits getCredit(User user){
		
		String hqlString = "FROM Credits c WHERE c.flag=? AND c.user = ? AND c.releaseDate>="+(new SimpleDateFormat("yyyy-MM-dd")).format(new Date());
		
		Object[] parameters = { Constant_Credits.CHECKIN+"",user };

		return  (Credits) this.executeQueryUniqueResult(hqlString, parameters);
		
	}
	
	public void saveCredit(Credits credits){
		this.savObject(credits);
	}
	
}
